<template>
  <div class="echart" id="myChartBar" :style="{float:'left',width: '100%', height: '230px'}"></div>
</template>

<script>
  import api from "../../../../axios/api"
    export default {
      name: "studentScoreBar",
      // mounted(){
      //     this.drawLine();
      // },
      data(){
        return {

          option:{
            color: ['#3398DB'],
            tooltip:{},
            title:'',
            xAxis: {
              data: []
            },
            yAxis:{
              type: 'value',
            },
            series: [{
              name: '分数',
              type: 'bar',
              data: []
            }],
            legend: {
              data:['分数']
            },
          }
        }
      },
      methods: {
        drawLine(){
          let myChart = this.$echarts.init(document.getElementById('myChartBar'))
          // 绘制图表
          myChart.setOption(this.option);
        },

        //根据id查询学生信息
        getScoreBySno:function(){
          let _this = this;
          api.setDataFromAxios("/api/TestWeb/studentController/getScoreBySno/09010101",null,"post",null).then(
            dto=>{
              let scs = dto.tList;
              let xData = [];
              let seriesData = [];
              for (var i=0;i<scs.length;i++){
                let sc = scs[i];
                xData.push(sc.course.cname);
                seriesData.push(sc.score);
                console.log(sc.score)
              }
              this.option.xAxis.data = xData;
              this.option.series[0].data = seriesData;

      this.drawLine();
            }
          )
        },
      },
      created() {
        this.getScoreBySno();
      }

    }
</script>

<style scoped>

</style>
